package com.tanhua.server.controller;

import com.tanhua.server.service.CommentsService;
import com.tanhua.server.service.MovementsMqService;
import com.tanhua.server.service.MovementsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/comments")
public class CommentsController {

    @Autowired
    private CommentsService commentsService;
    @Autowired
    private MovementsService movementsService;
    @Autowired
    private MovementsMqService movementsMqService;

    @GetMapping(name="查询某一个动态的评论数据")
    public ResponseEntity queryCommentsList(
            String movementId,
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10")  Integer pagesize){
      return commentsService.queryCommentsList(movementId,page,pagesize);
    }

    @PostMapping(name="发布评论")
    public ResponseEntity saveComment(@RequestBody Map map){
        String movementId = (String) map.get("movementId"); //当前圈子动态id
        String comment = (String) map.get("comment"); //发表的言论
        movementsMqService.sendMsg(movementId,4);
        return commentsService.saveComment(movementId,comment);
    }

    @GetMapping(value = "/{id}/like",name = "对评论动态点赞")
    public ResponseEntity likeComment(@PathVariable("id") String publishId) throws Exception{
//        评论内容类型： 1-对圈子动态操作 2-对视频操作 3-对评论操作
        return  movementsService.likeComment(publishId,3);
    }
    @GetMapping(value = "/{id}/dislike",name = "对评论动态取消点赞")
    public ResponseEntity dislikeComment(@PathVariable("id") String publishId) throws Exception{
//        评论内容类型： 1-对圈子动态操作 2-对视频操作 3-对评论操作
        return  movementsService.dislikeComment(publishId,3);
    }
}
